package com.xhh.nphm.gaoxin.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xhh.nphm.common.annotation.DataSource;
import com.xhh.nphm.common.constant.Constants;
import com.xhh.nphm.gaoxin.entity.GxqTworkFormLogEty;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository

public interface GxqTworkFormLogDao extends BaseMapper<GxqTworkFormLogEty> {
    /**
     * 工单日志 列表数据
     * @param wfId
     * @return
     */
    @Select("select LogId,WfId,convert(varchar(19),LogTime,20) as opTime,OpDeptName,OpUserName,OpAction,OpDesc,WsOpen,WsDesc,SpareString from tWorkFormLog where WfId=#{wfId} and IsDel=0 order by LogTime desc")
    List<GxqTworkFormLogEty> logListJson(@Param("wfId") int wfId);

    /**
     * 根据id查找一个工单操作日志
     * @param logId 日志id
     * @return 实体
     */
    @Select("select LogId,WfId,convert(varchar(19),LogTime,20) as opTime,OpDeptName,OpUserName,OpAction,OpDesc,WsOpen,WsDesc from tWorkFormLog where LogId = #{0} and IsDel=0")
    GxqTworkFormLogEty findById(Integer logId);

    /**
     * 切换日志公开状态
     * @param logId 日志id
     * @return 返回结果
     */
    @Update("update tWorkFormLog SET WsOpen = (CASE WHEN WsOpen = 0 THEN 1 ELSE 0 END) where LogId = #{0} and isDel = 0")
    int updateState(Integer logId);
}
